package com.example.udpDemo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * Description: 事件类型枚举
 *
 * @author sjt Administrator
 * @since 2023/12/3 16:23
 */
@Getter
@AllArgsConstructor
public enum EventEnum {
    UNKNOWN(0x0000, "未知"),
    MAIN_POWER_FAILURE(0x000B, "主电故障"),
    MAIN_POWER_RECOVERY(0x000C, "主电故障恢复"),
    REMOVED(0x0013, "已拆除"),
    HOST_COMMUNICATION_FAILURE(0x0015, "主机通讯故障"),
    HOST_COMMUNICATION_RECOVERY(0x0016, "主机通讯故障恢复"),
    SENSOR_FAILURE(0x0017, "传感器故障"),
    SENSOR_RECOVERY(0x0018, "传感器故障恢复"),
    SENSOR_COMMUNICATION_FAILURE(0x0024, "传感器通讯故障"),
    SENSOR_COMMUNICATION_RECOVERY(0x0025, "传感器通讯故障恢复"),
    ALARM_CLEAR(0x0032, "报警消除"),
    EARLY_WARNING(0x0033, "预警"),
    LOW_LIMIT_ALARM(0x0034, "低限报警"),
    HIGH_LIMIT_ALARM(0x0035, "高限报警"),
    SMOKE_ALARM(0x0038, "烟雾报警"),
    HIGH_TEMPERATURE_ALARM(0x0039, "高温报警"),
    OVER_RANGE(0x0040, "超量程"),
    SELF_CHECK(0x00CF, "自检"),
    SENSOR_LIFETIME_EXPIRED(0x00D5, "传感器寿命到期"),
    HEARTBEAT_SIGNAL(0x012A, "心跳信号"),
    POWER_ABNORMAL_INTERRUPT(0x012B, "供电异常中断"),
    ONLINE(0x012D, "上线");

    private final int code;
    private final String name;

    public static EventEnum getByCode(int code) {
        return Arrays.stream(EventEnum.values()).filter(v -> code == v.getCode()).findFirst().orElse(UNKNOWN);
    }
}
